From 75916090b45614cae2512437750208af61c24172 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 30 Aug 2006 20:34:20 +0000 Subject: [PATCH] Force usage of common gbfile api. 'textfile' is now part of the history of GPSBabel. --- gpsbabel/csv_util.c | 22 +++++++++------------- gpsbabel/csv_util.h | 2 +- gpsbabel/xcsv.c | 21 +++++++++------------ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index fdb14b7e9..3b0b907ea 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -1001,11 +1001,8 @@ xcsv_data_read(void) queue *elem, *tmp; field_map_t *fmp; ogue_t *ogp; - textfile_t *tin; - tin = textfile_init(xcsv_file.xcsvfp); - - while ((buff = textfile_read(tin))) { + while ((buff = gbfgetstr(xcsv_file.xcsvfp))) { linecount++; buff = lrtrim(buff); @@ -1061,7 +1058,6 @@ xcsv_data_read(void) } } - textfile_done(tin); } static void @@ -1150,7 +1146,7 @@ xcsv_waypt_pr(const waypoint *wpt) fmp = (field_map_t *) elem; if ((i != 0) && !(fmp->options & OPTIONS_NODELIM)) - fprintf (xcsv_file.xcsvfp, write_delimiter); + gbfprintf (xcsv_file.xcsvfp, write_delimiter); if (fmp->options & OPTIONS_ABSOLUTE) { lat = fabs(lat); @@ -1454,16 +1450,16 @@ xcsv_waypt_pr(const waypoint *wpt) * ""%s"" to smuggle bad characters through. */ if (0 == strcmp(fmp->printfc, "\"%s\"")) { - fprintf (xcsv_file.xcsvfp, "\"%s\"", obuff); + gbfprintf (xcsv_file.xcsvfp, "\"%s\"", obuff); } else { - fprintf (xcsv_file.xcsvfp, "%s", obuff); + gbfprintf (xcsv_file.xcsvfp, "%s", obuff); } next: xfree(obuff); } - fprintf (xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); + gbfprintf (xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); if (description && description != shortname) xfree(description); @@ -1502,12 +1498,12 @@ xcsv_data_write(void) ol = strsub(ogp->val, "__FILE__", xcsv_file.fname); if (ol) { - fprintf(xcsv_file.xcsvfp, "%s", ol); + gbfprintf(xcsv_file.xcsvfp, "%s", ol); xfree(ol); } else { - fprintf(xcsv_file.xcsvfp, "%s", ogp->val); + gbfprintf(xcsv_file.xcsvfp, "%s", ogp->val); } - fprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); + gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); } waypt_disp_all(xcsv_waypt_pr); @@ -1517,7 +1513,7 @@ xcsv_data_write(void) /* output epilogue lines, if any. */ QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) { ogp = (ogue_t *) elem; - fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter); + gbfprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter); } } #endif diff --git a/gpsbabel/csv_util.h b/gpsbabel/csv_util.h index c93cc6e9b..8da2d3e2a 100644 --- a/gpsbabel/csv_util.h +++ b/gpsbabel/csv_util.h @@ -123,7 +123,7 @@ typedef struct { int ifield_ct; /* actual # of ifields */ int ofield_ct; /* actual # of ofields */ - FILE * xcsvfp; /* ptr to current *open* data file */ + gbfile * xcsvfp; /* ptr to current *open* data file */ char * fname; /* ptr to filename of above. */ char * description; /* Description for help text */ diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index 64a4ff34e..32837cd8b 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -441,18 +441,16 @@ static void xcsv_read_style(const char *fname) { char *sbuff; - FILE *fp; - textfile_t *tin; + gbfile *fp; xcsv_file_init(); - fp = xfopen(fname, "rb", MYNAME); - tin = textfile_init(fp); + fp = gbfopen(fname, "rb", MYNAME); - while ((sbuff = textfile_read(tin))) { + while ((sbuff = gbfgetstr(fp))) { sbuff = lrtrim(sbuff); xcsv_parse_style_line(sbuff); - } while (!feof(fp)); + } while (!gbfeof(fp)); /* if we have no output fields, use input fields as output fields */ if (xcsv_file.ofield_ct == 0) { @@ -461,8 +459,7 @@ xcsv_read_style(const char *fname) xcsv_file.ofield = &xcsv_file.ifield; xcsv_file.ofield_ct = xcsv_file.ifield_ct; } - textfile_done(tin); - fclose(fp); + gbfclose(fp); } /* @@ -519,14 +516,14 @@ xcsv_rd_init(const char *fname) warning(MYNAME " attempt to read %s as a track or route, but this module only supports waypoints on read. Reading as waypoints instead.\n", fname); } - xcsv_file.xcsvfp = xfopen(fname, "r", MYNAME); + xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME); } static void xcsv_rd_deinit(void) { - fclose(xcsv_file.xcsvfp); + gbfclose(xcsv_file.xcsvfp); xcsv_destroy_style(); } @@ -548,7 +545,7 @@ xcsv_wr_init(const char *fname) xcsv_read_style(styleopt); } - xcsv_file.xcsvfp = xfopen(fname, "w", MYNAME); + xcsv_file.xcsvfp = gbfopen(fname, "w", MYNAME); xcsv_file.fname = (char *)fname; /* set mkshort options from the command line */ @@ -575,7 +572,7 @@ xcsv_wr_init(const char *fname) static void xcsv_wr_deinit(void) { - fclose(xcsv_file.xcsvfp); + gbfclose(xcsv_file.xcsvfp); xcsv_destroy_style(); } -- 2.30.2